package com.gdufe.mistakebook.exception;

import com.gdufe.mistakebook.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一异常处理类
 *
 * @author lzh
 */
@RestControllerAdvice
@Slf4j(topic = "GlobalExceptionHandler.class")
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public static Result<String> error(BusinessException be) {
        // 控制台输出报错日志
        log.error("服务器发生异常：" + be.getMessage());
        return Result.error(be.getMessage());
    }
}
